//
//  LVView.m
//  PetAPP
//
//  Created by dllo on 16/1/25.
//  Copyright © 2016年 Yuming. All rights reserved.
//

#import "LVView.h"
#import "ModelOfHeaderInfo.h"
#import <YYWebImage.h>

@interface LVView ()

@property (nonatomic, retain) UIImageView *imageView;

@property (nonatomic, retain) UILabel *labelOfName;

@end

@implementation LVView

- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViewsWithFrame:(CGRect){.size = frame.size}];
        
    }

    return self;
}

- (void)handleDataWithModel:(ModelOfHeaderInfo *)model {
    
    self.imageView.yy_imageURL = [NSURL URLWithString:model.img];
    self.labelOfName.text = model.name;

}

- (void)createSubViewsWithFrame:(CGRect)frame {
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, frame.size.height - 10 - 30, frame.size.height - 10 - 30)];
    
    [self addSubview:self.imageView];
    [_imageView release];
    
//    self.button.layer.cornerRadius = (frame.size.height - 10 - 20) / 2.0;
    
    self.labelOfName = [[UILabel alloc] initWithFrame:CGRectMake(10, 5 + frame.size.height - 10 - 20, frame.size.height - 10 - 20,  20)];
    [self addSubview:self.labelOfName];
    [_labelOfName release];
    
    self.labelOfName.textAlignment = NSTextAlignmentCenter;
    
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSString *num = nil;
    NSDictionary *dic = nil;
    if (self.tag == 1) {
        dic = @{@"url" : @"http://api.leepet.com/?m=DZ&a=foundPetLst",
                              @"body": @"lat=38.88957190&lng=121.55119110&page=1&pagesize=10&uid=1411934&version=d1bd83a33f1a841ab7fda32449746cc4",
                              @"value": @{@"Content-Type" : @"application/x-www-form-urlencoded"}};
        num = @"1";
    }else if (self.tag == 2) {
    
        dic = @{@"url" : @"http://bbs.chinapet.com/plugin.php?id=leepet_thread:api&action=activityListNew",
                              @"body": @"page=1&pagesize=10&version=d1bd83a33f1a841ab7fda32449746cc4",
                              @"value": @{@"Content-Type" : @"application/x-www-form-urlencoded"}};
        num = @"2";
    }else {
    
        dic = @{@"url" : @"http://bbs.chinapet.com/plugin.php?id=leepet_thread:api&action=indexmygroup",
                              @"body": @"version=d1bd83a33f1a841ab7fda32449746cc4",
                              @"value": @{@"Content-Type" : @"application/x-www-form-urlencoded"}};
        num = @"3";
    
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PushLVView" object:num userInfo:dic];

}



- (void)dealloc {

    [_labelOfName release];
    [_imageView release];
    [super dealloc];
}


@end
